<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <link href="./css/api.css" rel="stylesheet"/>
  <link href="./css/element.css" rel="stylesheet"/>
  <link href="./css/base.css" rel="stylesheet"/>
  <title>登录</title>
</head>
<body>
  <div id="vm" v-cloak>
    <div class="x-login">
      <div class="x-close-login">登录</div>
      <div class="x-login-pro">
        <div class="x-login-t">人才管理系统账号登录</div>
        <el-form :model="loginForm" :rules="rules" ref="loginForm">
          <el-form-item prop="username" class="x-login-username">
            <el-input v-model="loginForm.username" placeholder="手机号" clearable></el-input>
          </el-form-item>
          <el-form-item prop="password" class="x-login-password">
            <el-input v-model="loginForm.password" placeholder="密码" clearable type="password"></el-input>
          </el-form-item>
          <el-form-item>
            <div class="x-btn" @click="gologin('loginForm')"><el-button type="danger">登录</el-button></div>
          </el-form-item>
        </el-form>
      </div>
    </div>
  </div>
  <script type="text/javascript" src="./script/vue.js"></script>
  <script type="text/javascript" src="./script/element.js"></script>
  <script type="text/javascript" src="./script/api.js"></script>
  <script type="text/javascript" src="./js/base.js"></script>
  <script>
    apiready = function () {

      //
    var vm = new Vue({
      el:'#vm',
      data(){
        return{
          loginForm:{
            username:'',
            password:''
          },
          rules:{
            username:[
              {required:true,message:'请输入账号',trigger:'blur'}
            ],
            password:[
              {required:true,message:'请输入密码',trigger:'blur'}
            ]
          }
        }
      },
      created:function() {
        var that=this;

      },
      mounted:function(){
        var that=this;

      },
      methods: {
        gologin:function(loginForm){
          api.showProgress();
          var that=this;
          that.$refs[loginForm].validate((valid) => {
            if(valid){
              console.log('ok');
              that.loginajax()
            }else{
              console.log('no');
              api.hideProgress();
            }
          })
        },
        loginajax:function(){
          var that=this;
          api.ajax({
            url:manaurl+'login',
            methods:'get',
            data:{
              values:{
                account: that.loginForm.username,
                password:that.loginForm.password
              }
            }
          },function(ret,err){
            if(ret){
              api.hideProgress();
              console.log(JSON.stringify(ret));
              if(ret.status == 1){

                api.toast({
                    msg: '登录成功',
                    duration: 3000,
                    location: 'bottom'
                });
                api.sendEvent({
                    name: 'loginsucc',
                    extra: {}
                });
                $api.setStorage('username', ret.data.username);
                $api.setStorage('userhead', ret.data.avatar);
                $api.setStorage('userarea', ret.data.area);
                $api.setStorage('usertoken', ret.data.token_str);

                api.closeWin();

              }else{
                api.toast({
                    msg: ret.msg,
                    duration: 3000,
                    location: 'bottom'
                });
              }
            }else{
              api.hideProgress();
              console.log(JSON.stringify(err));
              api.toast({
                  msg: err.msg,
                  duration: 3000,
                  location: 'bottom'
              });
            }
          })
        },
      }
    })
    }
  </script>
</body>
</html>
